Striver A2Z DSA Sheet
A complete, step-by-step roadmap to master Data Structures & Algorithms, curated by Striver — from basics to advanced topics.
Basics (1)
Get started with time complexity, patterns, and basic math.
→Sorting (3)
Learn popular sorting algorithms and their time complexities.
→Array (22)
Learn array fundamentals, sorting, and sliding window problems.
→Binary Search (22)
Binary search on arrays, answers, and advanced patterns.
→Strings
String manipulation, hashing basics, and common interview problems.
→Linked List
Singly, doubly, and circular linked list problems.
→Recursion & Backtracking
Recursion basics, subsets, permutations, and backtracking problems.
→Bit Manipulation
Learn bit tricks, XOR properties, and optimization techniques.
→Stack & Queue
Stack, queue, monotonic stack, and implementation problems.
→Sliding Window & Two Pointer
Efficient range-based problems using optimized pointers.
→Heaps / Priority Queue
Min-heap, max-heap, and top-K problems.
→Greedy Algorithms
Activity selection, interval problems, and optimization strategies.
→Binary Trees
Traversals, height, diameter, and path-based problems.
→Binary Search Trees
BST properties, insert/delete/search operations.
→Graphs
BFS, DFS, shortest paths, and cycle detection.
→Dynamic Programming
Memoization, tabulation, and pattern-based DP problems.
→Tries
Prefix trees, autocomplete systems, and string optimization.
→Question
Whats the differences between brute force and constructive algorithm?
The difference between brute force and constructive algorithm is mainly about how the solution is obtained.
Brute Force Approach
A brute force algorithm tries all possible possibilities until it finds the correct answer.
Idea
Exhaustively check every possible case.
Characteristics
- Simple to implement
- Often slow
- Works for small inputs
- Guarantees finding the correct answer (if implemented correctly)
Example
Find two numbers in an array that sum to k.
Brute force:
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(a[i] + a[j] == k)
cout << i << " " << j;
}
}
Complexity:
It checks every pair.
Constructive Algorithm
A constructive algorithm builds the solution step by step using logic or patterns, without checking all possibilities.
Idea
Directly construct a valid answer.
Characteristics
- Uses mathematical insight or problem pattern
- Much faster
- Common in competitive programming
- Doesn't try every possibility
Example
Problem:
Print a permutation of 1..n such that no two adjacent numbers differ by 1.
Brute force idea:
- Generate all permutations
- Check each one
Complexity:
Constructive idea:
- Print all even numbers first, then all odd numbers
Example for n = 5:
2 4 1 3 5
Complexity:
Key Differences
| Feature | Brute Force | Constructive |
|---|---|---|
| Idea | Try everything | Build answer logically |
| Speed | Usually slow | Usually fast |
| Implementation | Easy | Requires insight |
| Typical complexity | (O(n^2), O(2^n), O(n!)) | Often (O(n)) |
Competitive Programming Context
In contests like Codeforces and AtCoder:
- Brute force is often used when constraints are small.
- Constructive algorithms appear in problems labeled constructive or math.
Simple summary
- Brute force: search for the answer.
- Constructive: build the answer directly.